<div id="information">
	<br /><br />

		<form action='' method='post' class='form'>
		<h3 class="form_h3">Заглавие</h3>
		<input type='text' name='title' value="<?php echo $_POST['title']; ?>"/>
		<h3 class="form_h3">Описание</h3>
		<textarea name='descr' cols='40' rows='5'><?php echo $_POST['descr']; ?></textarea>
		<br /><br />
		<input type='submit' name='submit' value='Запиши' />	
		</form>
	<?php
	$sel_username_f = mysql_query('SELECT * FROM users WHERE username = "'.$_SESSION['username'].'"');
	$row_u_f = mysql_fetch_assoc($sel_username_f);
	
	
		$title = htmlspecialchars(trim($_POST['title']));
		$descr = htmlspecialchars(trim($_POST['descr']));
		$type = $row_u_f['type'];
		$date = time();
		$username = $_SESSION['username'];
		
		if($_POST['submit']){
			if(!empty($title) && !empty($descr)) {
			    if(strlen($title) < 3 && strlen($descr) < 3){
				  echo '<p class="error">Кратко име и/или описание!</p>';
				} else {
				   $sel_cat = mysql_query('SELECT `cat_title` FROM categories WHERE `cat_title` = "'.$title.'"');
				   if(mysql_num_rows($sel_cat) != 0){
				      echo '<p class="error">Категорията съществува!</p>';
				   } else {
				      $ins_cat = 'INSERT INTO categories(who_added, user_type, cat_title, cat_descr, date) 
					  VALUES("'.$username.'", "'.$type.'", "'.$title.'", "'.$descr.'", "'.$date.'")';
					  $ins_car_qe = mysql_query($ins_cat);
				      echo '<p class="success">Успешен запис!</p>';
					  ?>
					  <meta http-equiv="refresh" content="0;url=forum.php">
					  <?php
				   }
				}
			} else {
			echo '<p class="error">Всички полета са задължителни!</p>';
			}
		}
	
	?>
	
	
	
	
	
	
	
	<br />
</div>